const basicAuth = require('basic-auth');
const jwt = require('jsonwebtoken');


//middlewares/exception.js
//这里的工作是捕获异常生成返回的接口
const catchError = async (ctx, next) => {
    try {
      await next();
    } catch (error) {
      console.log(error)
      if(error.errorCode) {
        ctx.body = {
          msg: error,
          error_code: 500,
          request: `${ctx.method} ${ctx.path}`
        };
      } else {
        //对于未知的异常，采用特别处理
        ctx.body = {
            data: '',
            msg: error,
            code: 500
        };
      }
    }
  }


exports.catchError = catchError;